package com.whw.fy.controller;

import com.whw.fy.entity.Message;
import com.whw.fy.entity.PlanSummarizeTable;
import com.whw.fy.service.PlanSummarizeTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@Api(tags = "训练计划模块")
@RestController
@RequestMapping("/api/planSummarizeTable")

public class PlanSummarizeTableController {
    @Resource
    private PlanSummarizeTableService planSummarizeTableService;

    @ApiOperation(value = "添加训练计划信息")
    @PostMapping("/one")
    public Message insert(PlanSummarizeTable planSummarizeTable) throws ParseException {
        return planSummarizeTableService.insertSelective(planSummarizeTable);
    }

    @ApiOperation(value = "删除训练计划")
    @DeleteMapping("/")
    public Message delete(Integer planSummarizeTableId) {
        return planSummarizeTableService.deleteByPrimaryKey(planSummarizeTableId);
    }

    @ApiOperation(value = "修改训练计划")
    @PutMapping("/")
    public Message update(PlanSummarizeTable planSummarizeTable) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        if (planSummarizeTable.getPlanSummarizeTableStarttimeToString()!=null)
            planSummarizeTable.setPlanSummarizeTableStarttime(simpleDateFormat.parse(planSummarizeTable.getPlanSummarizeTableStarttimeToString()));
        if (planSummarizeTable.getPlanSummarizeTableFinishtimeToString()!=null)
            planSummarizeTable.setPlanSummarizeTableFinishtime(simpleDateFormat.parse(planSummarizeTable.getPlanSummarizeTableFinishtimeToString()));
        return planSummarizeTableService.updateByPrimaryKeySelective(planSummarizeTable);
    }

    @ApiOperation(value = "获取训练计划")
    @GetMapping("/one")
    public Message selectByPrimaryKey(Integer planSummarizeTableId){
        return planSummarizeTableService.selectByPrimaryKey(planSummarizeTableId);
    }

    @ApiOperation(value = "获取所有训练计划")
    @GetMapping("/all")
    public Message selectAll(){
        return planSummarizeTableService.selectAll();
    }

}
